package com.hsjry.quartz.chapter1;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

/**
 * 
 * @author giegie
 * 
 */
public class QuartzTest1 {
	public static void main(String[] args) throws SchedulerException {
		JobDetail jobDetail = JobBuilder//
				.newJob(HelloJob.class)//
				.withIdentity("testJob_1", "group_1")//
				.build();
		jobDetail.getJobDataMap().put("name_", "wangjie");
		
		Trigger trigger = TriggerBuilder//
				.newTrigger()//
				.withIdentity("trigger_1", "group_1")//
				.startNow()//
				.withSchedule(//
						SimpleScheduleBuilder.simpleSchedule()//
								.withIntervalInSeconds(1) // 时间间隔
								.withRepeatCount(5) // 重复次数(将执行6次！！！)
				).build();
		SchedulerFactory sf = new StdSchedulerFactory();
		Scheduler sched = sf.getScheduler();

		sched.scheduleJob(jobDetail, trigger);

		sched.start();
	}
}
